import pandas as pd
from pyecharts.charts import Pie
from pyecharts import options as opts

df = pd.read_csv('D:\\Flask项目\\Scarpy_bilibili\\blbl\\blbl\\bilibili.csv')
print(df)
df_without_all=df[~df['rank_tab'].isin(['全站'])]   #把全站榜数据排除
def count_genre_top100(df):
    genres_rank_Series=df.sort_values(by='score', ascending=False)[:100]['rank_tab']  # 降序排序
    genres_rank_count=genres_rank_Series.value_counts()   # 使用value_counts方法快速得到各分区出现的次数
    print(type(genres_rank_count))
    print(genres_rank_count)
    return genres_rank_count
count_genre=count_genre_top100(df_without_all)
def pie_rosrtype(df):
    c=(
        Pie()
        .add(
            '',
            [list(z) for z in zip(df.index, df)],
            radius=['30%', '75%'],
            center=['50%', '50%'],
            rosetype="radius",
        )
        .set_global_opts(title_opts=opts.TitleOpts(title='top100分类占比 '))  # 总标签

        .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{c}"))  # 设置分标签，展现形式为标签：数值
    )
    return c
pie=pie_rosrtype(count_genre)
pie.render('rose_pic.html')